package com.google.code.sip.ucenter.dao.mongo;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import com.google.code.sip.core.dao.mongo.GenericMongoDao;
import com.google.code.sip.ucenter.dao.FriendDao;
import com.google.code.sip.ucenter.model.Friend;
import com.google.code.sip.ucenter.model.FriendGroup;
import com.google.code.sip.ucenter.model.User;

public class FriendDaoImpl extends GenericMongoDao<Friend, String> implements
		FriendDao {

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.google.code.sip.ucenter.dao.mongo.FriendDao#getFriends(com.google.code
	 * .ucenter.model.User)
	 */
	public List<Friend> getFriends(User user) {
		return this.findByProperty("user", user);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.google.code.sip.ucenter.dao.mongo.FriendDao#getFriend(com.google.code
	 * .ucenter.model.User, com.google.code.sip.ucenter.model.User)
	 */
	public Friend getFriend(User user, User friendUser) {
		Map<String, Object> filters = new LinkedHashMap<String, Object>();
		filters.put("user", user);
		filters.put("friend", friendUser);
		return this.getByProperties(filters);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.google.code.sip.ucenter.dao.mongo.FriendDao#getFriends(com.google.code
	 * .ucenter.model.FriendGroup)
	 */
	public List<Friend> getFriends(FriendGroup friendGroup) {
		return this.findByProperty("friendGroup", friendGroup);
	}
}
